import http from "../utils/request"
import {PageRequestType, ResponseType, PageResponseType} from "../types/Response";
import {AxiosResponse} from "axios";

const apiPrefix:string = "/order";

export interface SearchOrderType{
    state?:number  // 订单状态（1为待支付，2为已支付待发货，3为已发货，4为已收货）
    current?:number
    size?:number
}

export async function searchOrderByPage(params:SearchOrderType):Promise<AxiosResponse<ResponseType<any>>>{
    return http.request({
        url:apiPrefix+'/my/page',
        method:'get',
        params
    })
}
export async function searchOrderById(id:string):Promise<AxiosResponse<ResponseType<any>>>{
    return http.request({
        url:apiPrefix+'/id',
        method:'get',
        params:{
            id
        }
    })
}

export async function createOrder(data:any):Promise<AxiosResponse<ResponseType<any>>>{
    return http.request({
        data,
        url:apiPrefix+'/create/good',
        method:'post'
    })
}


export async function postOrder(data:any):Promise<AxiosResponse<ResponseType<any>>>{
    return http.request({
        url:apiPrefix+'/good',
        method:'post',
        data
    })
}
export async function cancelOrder(orderId:string):Promise<AxiosResponse<ResponseType<any>>>{
    return http.request({
        url:apiPrefix+'/cancel',
        method:'delete',
        params:{
            orderId
        }
    })
}
export async function payOrder(id:string):Promise<AxiosResponse<ResponseType<any>>>{
    return http.request({
        url:apiPrefix+'/pay',
        method:'post',
        data:{
            id
        }
    })
}
export async function finishOrder(id:string):Promise<AxiosResponse<ResponseType<any>>>{
    return http.request({
        url:apiPrefix+'/finish',
        method:'post',
        data:{
            id
        }
    })
}
